//
//  SocialViewArticlesPreviewCell.swift
//  iModern
//
//  Created by Ralf on 7/6/15.
//  Copyright (c) 2015 com.starlooking. All rights reserved.
//

import UIKit

class SocialViewArticlesPreviewCell: TableViewCell
{
    let max    = 4
    var width: CGFloat!
    var images = [UIImageView]()

    override func awakeFromNib()
    {
        super.awakeFromNib()

        width = self.screen.size.width / 5 - 5

        for var i = 0; i < max; i++
        {
            //let left = self.screen.width / 5 - 5.0 * 4

            let x = (self.screen.size.width / 5) * CGFloat(i + 1) - 10

            let frame     = CGRect(x: x, y: 0, width: width, height: width)
            let imageView = UIImageView(frame: frame)
            images.append(imageView)

            imageView.layer.borderWidth = 1.0
            imageView.layer.borderColor = UIColor.blackColor().CGColor
            imageView.layer.masksToBounds = true
            imageView.layer.cornerRadius = width * 0.4

            self.addSubview(imageView)
        }
    }

    override func setSelected(selected: Bool, animated: Bool)
    {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }

    func setData(data: [[String:AnyObject]]?)
    {
        for var i = 0; i < max; i++
        {
            images[i].image = nil
            images[i].hidden = true
        }

        for var i = 0; i < max && i < data?.count; i++
        {
            images[i].hidden = false
            let article      = data?[i]
            let thumbnailURL = article?["thumbnailURL"] as! String
            let imageView    = images[i]

//            imageView.layer.shadowColor = UIColor.blackColor().CGColor
//            imageView.layer.shadowOpacity = 0.2
//            imageView.layer.shadowOffset = CGSizeMake(1.0, 1.0)
//            imageView.layer.shadowRadius = 1.0
//            imageView.layer.masksToBounds = false

            let url = appDelegate.parameterManager.server + "/" + thumbnailURL
            imageView.load(url, placeholder: nil)
        }
    }
}
